import router from './router'
import store from './store'
import { Message } from 'element-ui'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import getPageTitle from '@/utils/get-page-title'

NProgress.configure({ showSpinner: false }) // NProgress Configuration

const whiteList = [
  '/'
] // no redirect whitelist

router.beforeEach((to, from, next) => {
  // start progress bar
  NProgress.start()
  const addr = store.getters.addr
  store.dispatch('user/loginMetamask', addr)
  // console.log('permissions.js==>>beforeEach', '#to', to.path,
  //   '#from', from.path, '#meta', to.meta, '#addr', addr)
  // set page title
  document.title = getPageTitle(to.meta.title) || 'Forsage'
  next()
  NProgress.done()
})

router.afterEach(() => {
  // finish progress bar
  NProgress.done()
})
